package com.itdct.onflow.core.config

import com.itdct.onflow.core.util.ProjectRsaUtil
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties
import org.jasypt.encryption.StringEncryptor
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
 * @author Zhouwx
 * @date 2025/10/22 17:46:23
 * @version 1.0
 * @description
 */
@Configuration
@EnableEncryptableProperties
class JasyptConfig(
    val projectRsaUtil: ProjectRsaUtil
) {
    @Bean("jasyptStringEncryptor")
    fun stringEncryptor(): StringEncryptor {
        return object : StringEncryptor {
            override fun encrypt(message: String): String {
                return projectRsaUtil.publicKeyEncrypt(message)
            }

            override fun decrypt(encryptedMessage: String): String {
                return projectRsaUtil.privateKeyDecrypt(encryptedMessage)
            }
        }
    }
}